webhelm 1.0.44 → 1.0.46

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
@@ -42,7 +42,10 @@ The Extension is bundled with the npm Runtime and staged by WebHelm Daemon at `~
42
42
  check (`com.lalalic.webhelm.keepalive`, every 30 seconds) and the npm Runtime
43
43
  updater (`com.lalalic.webhelm.runtime-update`, every hour and at login).
44
44
  The updater checks the npm registry and downloads new releases to a temporary
45
- location without running npm lifecycle scripts. It validates that Runtime and
45
+ location without running npm lifecycle scripts. Each check and installation
46
+ uses an isolated, disposable npm cache rather than a potentially stale npx
47
+ cache. If npm release metadata has not propagated yet, it defers safely and
48
+ retries on the next scheduled check. It validates that Runtime and
46
49
  Extension versions match, stages an immutable copy under
47
50
  `~/.local/share/webhelm/runtime-VERSION`, and uses the stable
48
51
  `~/.local/share/webhelm/runtime-current` symlink for subsequent launches.
@@ -58,7 +61,12 @@ new daemon against the existing Chrome/profile/queue, and verifies its version.
58
61
  A busy daemon returns `deferred` and retries on the next scheduled run. A failed
59
62
  installation reverts the pointer and resumes the old queue. Unavailable npm or
60
63
  unrecognized old daemon upgrade protocols fail closed rather than killing a
61
- Session. The update log is at `~/.config/webhelm/runtime/auto-update.log`.
64
+ Session. For a one-time manual migration, `webhelm upgrade --force` verifies
65
+ the daemon PID/lock and sends SIGTERM before starting the new Runtime.
66
+ This bypasses idle checks and may interrupt active Sessions or running queue
67
+ workers; it does not deliberately restart Chrome. The scheduled updater
68
+ never uses `--force`. The update log is at
69
+ `~/.config/webhelm/runtime/auto-update.log`.
62
70
 
63
71
  Neo Master uses `WEBHELM_SOURCE_MODE=1` and runs its linked Git checkout, not
64
72
  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.46",
4
4
  "description": "Agent browser automation in a visible managed Chrome with persistent JavaScript sessions",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,17 +20,24 @@ export function compareVersions(a,b) {
20
20
  return 0;
21
21
  }
22
22
 
23
- export function npmLatest() {
24
- const value=execFileSync('npm',['view','webhelm','version','--json',`--registry=${REGISTRY}`,'--fetch-retries=0','--fetch-timeout=8000'],
25
- {encoding:'utf8',timeout:15000,stdio:['ignore','pipe','pipe']});
26
- const version=JSON.parse(value);
27
- compareVersions(version,version);
28
- return version;
23
+ // The Skill launcher may use a persistent npx cache with a stale packument.
24
+ // New versions can appear in npm view yet still fail ETARGET at npm install.
25
+ // Always query via an isolated, disposable npm cache.
26
+ export function npmLatest({run=execFileSync}={}) {
27
+ const cache=fs.mkdtempSync(path.join(os.tmpdir(),'webhelm-npm-metadata-'));
28
+ try{
29
+ const value=run('npm',['view','webhelm','version','--json','--registry='+REGISTRY,
30
+ '--cache='+cache,'--prefer-online','--fetch-retries=0','--fetch-timeout=8000'],
31
+ {encoding:'utf8',timeout:15000,stdio:['ignore','pipe','pipe']});
32
+ const version=JSON.parse(value);
33
+ compareVersions(version,version);
34
+ return version;
35
+ }finally{fs.rmSync(cache,{recursive:true,force:true});}
29
36
  }
30
37
 
31
38
  // npm installs into an isolated temporary prefix; lifecycle scripts never run.
32
39
  // The existing offline staging contract (Runtime + yaml) remains unchanged.
33
- export function downloadRuntime(version,{home=os.homedir()}={}) {
40
+ export function downloadRuntime(version,{home=os.homedir(),run=execFileSync}={}) {
34
41
  compareVersions(version,version);
35
42
  const cached=path.join(home,'.local/share/webhelm',`runtime-${version}`);
36
43
  try {
@@ -43,9 +50,10 @@ export function downloadRuntime(version,{home=os.homedir()}={}) {
43
50
  }catch{}
44
51
  const temp=fs.mkdtempSync(path.join(os.tmpdir(),'webhelm-npm-upgrade-'));
45
52
  try {
46
- execFileSync('npm',['install','--prefix',temp,'--no-save','--omit=dev','--ignore-scripts',
53
+ run('npm',['install','--prefix',temp,'--no-save','--omit=dev','--ignore-scripts',
47
54
  '--no-audit','--no-fund','--package-lock=false','--fetch-retries=0',
48
- `--registry=${REGISTRY}`,`webhelm@${version}`],
55
+ '--registry='+REGISTRY,'--cache='+path.join(temp,'.npm-cache'),
56
+ '--prefer-online','webhelm@'+version],
49
57
  {timeout:120000,stdio:['ignore','pipe','pipe']});
50
58
  const source=path.join(temp,'node_modules/webhelm');
51
59
  const manifest=JSON.parse(fs.readFileSync(path.join(source,'package.json'),'utf8'));
@@ -77,12 +85,39 @@ function acquireLock(home) {
77
85
  return null;
78
86
  }
79
87
 
88
+ // Explicit --force only. Verify the PID against the local daemon lock and
89
+ // live IPC identity before sending SIGTERM. Never signal managed Chrome.
90
+ export async function forceStopDaemon(daemon,{home=os.homedir(),ipc=req=>request(req,false),
91
+ lockPath=process.env.WEBHELM_LOCK||path.join(home,'.config/webhelm/runtime/session-node.lock'),
92
+ signal=process.kill,inspect=pid=>execFileSync('ps',['-p',String(pid),'-o','command='],
93
+ {encoding:'utf8',timeout:5000}),timeoutMs=30000}={}) {
94
+ const pid=daemon?.pid;
95
+ if(!Number.isSafeInteger(pid)||pid<=1||pid===process.pid)
96
+ throw Error('Refusing forced upgrade: invalid daemon PID');
97
+ const owner=Number(fs.readFileSync(lockPath,'utf8').trim());
98
+ if(owner!==pid)throw Error('Refusing forced upgrade: daemon lock PID mismatch');
99
+ const command=await inspect(pid);
100
+ if(!/node-daemon\.mjs\s+daemon(?:\s|$)/.test(command))
101
+ throw Error('Refusing forced upgrade: PID is not a WebHelm daemon');
102
+ const live=await ipc({op:'ping'});
103
+ if(live?.pid!==pid||live.version!==daemon.version)
104
+ throw Error('Refusing forced upgrade: daemon identity changed');
105
+ signal(pid,'SIGTERM');
106
+ const deadline=Date.now()+timeoutMs;
107
+ while(Date.now()<deadline){
108
+ // Lock removal follows shutdown cleanup, including queue worker teardown.
109
+ if(!fs.existsSync(lockPath))return {stopping:true,stopped:true,pid};
110
+ await sleep(100);
111
+ }
112
+ return {stopping:true,stopped:false,pid};
113
+ }
114
+
80
115
  // Inject ports for isolated tests. Production never imports npm code or
81
116
  // touches another Chrome profile to decide whether to upgrade.
82
117
  export async function upgradeRuntime({home=os.homedir(),source=SOURCE,nodePath=process.execPath,
83
118
  latest=npmLatest,download=downloadRuntime,ipc=req=>request(req,false),
84
119
  installGuard=installLoginGuard,installPoller=installRuntimeUpdate,
85
- activate=activateRuntime,verify=null,apply=true}={}) {
120
+ activate=activateRuntime,verify=null,restart=forceStopDaemon,apply=true,force=false}={}) {
86
121
  if(process.env.WEBHELM_SOURCE_MODE==='1')return {status:'source_checkout',upgraded:false};
87
122
  const unlock=acquireLock(home);
88
123
  if(!unlock)return {status:'already_running',upgraded:false};
@@ -100,11 +135,20 @@ export async function upgradeRuntime({home=os.homedir(),source=SOURCE,nodePath=p
100
135
  const upToDate=daemon?.version===target && currentTarget &&
101
136
  fs.existsSync(path.join(currentTarget,'package.json')) &&
102
137
  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})};
138
+ if(upToDate&&!force)return {status:'current',upgraded:false,version:target,global_cli:migrateLegacyRuntimeCli({home})};
104
139
  // Stage before requesting the daemon to drain; download may take time.
105
- const staged=compareVersions(target,local)>0
106
- ? await download(target,{home}) : stageRuntimeForLoginGuard({home,source});
107
- if(daemon && compareVersions(daemon.version,target)<0){
140
+ let staged;
141
+ try{
142
+ staged=compareVersions(target,local)>0
143
+ ? await download(target,{home}) : stageRuntimeForLoginGuard({home,source});
144
+ }catch(error){
145
+ const cause=String(error.stderr||'')+' '+String(error.message||'');
146
+ if(/\b(?:ETARGET|ENOVERSIONS|E404)\b/.test(cause))
147
+ return {status:'deferred',upgraded:false,reason:'npm_release_not_yet_resolvable',
148
+ latest:target,detail:'npm registry or cache has not propagated the release; retry later'};
149
+ throw error;
150
+ }
151
+ if(!force && daemon && compareVersions(daemon.version,target)<0){
108
152
  let gate;
109
153
  try{gate=await ipc({op:'upgrade-prepare'});}
110
154
  catch(error){return {status:'deferred',upgraded:false,reason:'daemon_upgrade_protocol_unavailable',detail:error.message,latest:target};}
@@ -119,7 +163,14 @@ export async function upgradeRuntime({home=os.homedir(),source=SOURCE,nodePath=p
119
163
  const poller=installPoller({home,cliPath,nodePath,apply});
120
164
  if(['staged_not_loaded','skipped'].includes(guard.status)||
121
165
  ['staged_not_loaded','skipped'].includes(poller.status))throw Error('Runtime LaunchAgent activation failed');
122
- if(prepared){
166
+ if(force && daemon){
167
+ const stopped=await restart(daemon,{home,ipc});
168
+ if(!stopped?.stopping)throw Error('Forced daemon restart was not accepted');
169
+ committed=true;
170
+ if(!stopped.stopped)return {status:'deferred',upgraded:false,
171
+ reason:'daemon_shutdown_timeout',daemon_pid:daemon.pid,latest:target,
172
+ forced:true,warning:'SIGTERM sent; runtime pointer updated but daemon has not completed shutdown'};
173
+ }else if(prepared){
123
174
  const result=await ipc({op:'upgrade-commit'});
124
175
  if(!result?.stopping)throw Error('Daemon did not accept Runtime cutover');
125
176
  prepared=false;committed=true;
@@ -137,7 +188,8 @@ export async function upgradeRuntime({home=os.homedir(),source=SOURCE,nodePath=p
137
188
  const state=await run();
138
189
  if(state.version!==target)throw Error(`Cutover verification failed: ${state.version} !== ${target}`);
139
190
  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};
191
+ daemon_pid:state.daemon?.pid||null,global_cli,guard:guard.status,auto_update:poller.status,
192
+ ...(force?{forced:true,sessions_before_restart:daemon?.session_count??null}:{})};
141
193
  }catch(error){
142
194
  // Never point new clients at an old Runtime after a committed daemon
143
195
  // 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.46",
5
5
  "description": "Own named Chrome tab-group workspaces and lazy reusable tab pools for browser agents.",
6
6
  "permissions": [
7
7
  "storage",